const express = require('express');
const router = express.Router();
const mysql = require('mysql');
const bodyParser = require('body-parser');
const connection = mysql.createConnection({
    host: '127.0.0.1',
    user: 'root',
    password: '12345678',
    database: 'internetcafe'
});
connection.connect(function (err) {
    if (err) {
        console.error('连接失败: ' + err.stack);
        return;
    }
    console.log('连接成功 id ' + connection.threadId);
})
const urlencodeParser = bodyParser.urlencoded({
    extended: true,
    limit: '50mb'
});
router.get('/login', (req, res) => {
    let data = req.query;
    console.log(data.username,data.pwd);
    connection.query('select * from admin where username="' + data.username + '" and pwd = "' + data.pwd + '"', function (err, result) {
        if (err) {
            console.log(err);
            res.json({
                code: 0,
                msg:"服务器500"
            })
        } else {
            console.log(result);
            res.jsonp( result);
        }
    })
});
module.exports = router;